﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using nspJob;
using Base;
using Ajax;

public partial class Job_ResumeManager : System.Web.UI.Page
{
    public string mino = "";
    public string fTypelist = "";
    public DataTable ftypeTab = new DataTable();
    public string typeid = "0";
    public string sendtypeid = "0";
    public string minotypeid = "0";
    protected void Page_Load(object sender, EventArgs e)
    {
        Ajax.Utility.RegisterTypeForAjax(typeof(Job_ResumeManager));
        if (!IsPostBack)
        {
            if (Request.Cookies["uName"] == null)
            {
                Response.Write("<script>location.assign('Index.aspx');</script>");
            }
            else
            {
                PositionTypeBind();
                Bind();
            }
        }
    }
    [Ajax.AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
    public string getTypeList(int id, string selID)
    {
        string list = "";
        Rjob jobtype = new Rjob();
        DataTable dt = jobtype.GetJobTypeByFid(id);
        if (dt.Rows.Count != 0)
        {
            list = "<select name=\"dropType_sel2\" id=\"dropType_sel2\" style=\"width:104px;\"  onchange=\"minochangeID(this.value)\">";
            list += "<option value=\"0\">选择职位类别</option>";
            foreach (DataRow dr in dt.Rows)
            {
                string cstr = "";
                if (selID == dr["ID"].ToString())
                {
                    cstr = "selected";
                }
                list += "<option value=\"" + dr["ID"] + "\" " + cstr + ">" + dr["TypeName"] + "</option>";
            }
            list += "</select>";
        }
        return list;
    }
    ///**************************************************
    /// <summary>
    /// depiction：对职位类别绑定
    /// </summary>
    /// <param name="<参数名称>"><参数说明></param>
    /// <returns>
    ///<对方法返回值的说明，该说明必须明确说明返回的值代表什么含义>
    /// </returns>
    ///Create Date：2009-9-1
    ///**************************************************
    private void PositionTypeBind()
    {
        Rjob jobtype = new Rjob();
        ftypeTab = jobtype.GetJobTypeByFid(0);
    }
    public void Bind()
    {
        RResume re = new RResume();
        String uName = "";
        if (Request.Cookies["uName"] != null)
        {
            uName = Server.HtmlEncode(Request.Cookies["uName"].Value);
        }
        DataTable table = re.GetDataTableByUname(uName);
        if (table.Rows.Count != 0)
        {

            Rjob jobtype = new Rjob();

            DataTable tb = jobtype.GetDataTable("C_JobType", table.Rows[0]["talentType"].ToString());
            if (tb.Rows.Count != 0)
            {
                if (tb.Rows[0]["FID"].ToString() != "0")
                {
                    typeid = tb.Rows[0]["FID"].ToString();
                    sendtypeid = table.Rows[0]["talentType"].ToString();
                    SecTypeID.Value = table.Rows[0]["talentType"].ToString();
                }
                else
                {
                    typeid = table.Rows[0]["talentType"].ToString();
                }
                TypeID.Value = tb.Rows[0]["FID"].ToString();
            }

            ViewState["id"] = table.Rows[0]["ID"];
            this.txtPosition.Text = table.Rows[0]["WantPosition"].ToString();

            if (table.Rows[0]["Photo"].ToString() == "")
            {
                this.ImgUrl1.Value = "../Images/System/wutu.gif";
                this.ImgUrl.Src = "../Images/System/wutu.gif";
            }
            else
            {
                this.ImgUrl1.Value = table.Rows[0]["Photo"].ToString();
                this.ImgUrl.Src = table.Rows[0]["Photo"].ToString();
            }
            this.DrpSex.SelectedValue = table.Rows[0]["Sex"].ToString();
            this.txteducation.SelectedValue = table.Rows[0]["HighestEducation"].ToString();
            this.txtGraduteSchool.Text = table.Rows[0]["GraduateSchool"].ToString();
            this.txtNative.Text = table.Rows[0]["NativePlace"].ToString();
            this.minop.Value = table.Rows[0]["WantAddress"].ToString();
            this.txtAge.Text = Convert.ToDateTime(table.Rows[0]["DateofBirth"].ToString()).ToShortDateString();
            this.Radhunyin.SelectedValue = table.Rows[0]["MaritalStatus"].ToString();
            this.dropcomputer.SelectedValue = table.Rows[0]["ComputerRequest"].ToString();
            this.dropEnlish.SelectedValue = table.Rows[0]["EnglishRequest"].ToString();
            this.txtDescription.Text = table.Rows[0]["JobDescription"].ToString();
            this.txtPersonResum.Text = table.Rows[0]["PersResume"].ToString();
            this.dropsalary.SelectedValue = table.Rows[0]["WantSalary"].ToString();
            this.txtName.Text = table.Rows[0]["Name"].ToString();
            this.txtTelphone.Text = table.Rows[0]["Telephone"].ToString();
            this.txtEmail.Text = table.Rows[0]["Email"].ToString();
            this.txtQQ.Text = table.Rows[0]["QQ"].ToString();
            this.txtMobel.Text = table.Rows[0]["Mobile"].ToString();
            this.txtAddress.Text = table.Rows[0]["ContactAddress"].ToString();
            this.txtwork.SelectedValue = table.Rows[0]["txtwork"].ToString();
            mino = this.minop.Value;
            dropTypeID.Value = table.Rows[0]["talentType"].ToString();
            minotypeid = table.Rows[0]["talentType"].ToString();
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (minop.Value != "" && dropTypeID.Value != "0")
        {
            if (!this.IsValid)
            {
                return;
            }
            TResume tr = new TResume();
            RResume re = new RResume();
            try
            {
                tr.ID = Convert.ToInt32(ViewState["id"].ToString());
                tr.WantPosition = this.txtPosition.Text;
                tr.Photo = ImgUrl1.Value;
                tr.DateofBirth = Convert.ToDateTime(this.txtAge.Text.ToString());
                tr.GraduateSchool = this.txtGraduteSchool.Text;
                tr.WantAddress = this.minop.Value;
                tr.JobDescription = GetRequest.RemoveHTMLForEditor(this.txtDescription.Text);
                tr.NativePlace = txtNative.Text;
                tr.PersResume = GetRequest.RemoveHTMLForEditor(this.txtPersonResum.Text);
                tr.Name = this.txtName.Text;
                tr.QQ = this.txtQQ.Text;
                tr.Telephone = this.txtTelphone.Text;
                tr.Mobile = this.txtMobel.Text;
                tr.Email = this.txtEmail.Text;
                tr.ContactAddress = this.txtAddress.Text;
                tr.Txtwork = txtwork.SelectedValue;
                tr.MaritalStatus = Radhunyin.SelectedValue;
                tr.Sex = DrpSex.SelectedValue;
                tr.HighestEducation = txteducation.SelectedValue;
                tr.ComputerRequest = dropcomputer.SelectedValue;
                tr.EnglishRequest = dropEnlish.SelectedValue;
                tr.TalentType = dropTypeID.Value.ToString();
                tr.WantSalary = dropsalary.SelectedValue;
                int count = re.Update(tr);//修改简历
                this.divMessage.Visible = true;
                if (count > 0)
                {
                    this.divMessage.InnerHtml = "修改成功";
                    Rjob jobtype = new Rjob();
                    ftypeTab = jobtype.GetJobTypeByFid(0);
                }
                else
                {
                    this.divMessage.InnerHtml = "修改失败";
                    Rjob jobtype = new Rjob();
                    ftypeTab = jobtype.GetJobTypeByFid(0);
                }
                Bind();
            }
            catch (Exception error)
            {
                this.divMessage.InnerHtml = "系统繁忙，请稍后再试！";
                Rjob jobtype = new Rjob();
                ftypeTab = jobtype.GetJobTypeByFid(0);
            }
        }
        else
        {

            if (minop.Value == "")
            {
                divMessage.InnerHtml = "请选择工作地点！";
            }
            if (dropTypeID.Value == "0")
            {
                divMessage.InnerHtml = "请选择职位类别！";
            }
            Rjob jobtype = new Rjob();
            ftypeTab = jobtype.GetJobTypeByFid(0);
        }
    }
}
